[急]C++作业 二维数组

来源:百度知道 编辑:UC知道 时间:2024/06/14 18:03:13
根据下表计算个人所得税,要求利用一个二维数组存储工资分段值和税率,工资额由用户输入。
级数 级距 税率(%)
1 800元以下部分 0
2 800-1500 5
3 1500-3000 10
4 3000-6000 20
5 6000-9000 30
6 9000-12000 40
7 12000以上 45
还有 实现一个投票选举的程序,假设有8名候选人,利用随即数产生100张选票并统计,最后按选票多少排列.

#include <iostream>
using namespace std;

const int base[6][2] = {{800,5},{1500,10},{3000,20},{6000,30},{9000,40},{12000,45}};

int main()
{
cout<<"input youe sary:";
int sary;
cin>>sary;
float total = 0;
for(int i=5; i>=0; --i)
{
if(sary>=base[i][0])
{
total += base[i][1]*(sary-base[i][0]+1)/float(100);
sary = base[i][0]-1;
}
}
cout<<"You need pay tax:"<<total<<endl;
return 0;
}
//投票选举的程序(做人要知足阿)
#include <iostream>
#include <ctime>
using namespace std;

const char *men[8] = {"men1","men2","men3","men4","men5","men6","men7","men8"};

void changeInt(int &a, int &b)
{
a = a+b;
b = a-b;
a = a-b;
}

void p_sort(int sortArray[], int